/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.p10.miage.gestionnote.model;

import fr.p10.miage.gestionnote.modelservice.EcServices;
import fr.p10.miage.gestionnote.modelservice.EcsIntervenantServices;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gernni
 */
public class EcIntervenant {
     private int idF;
     private int idP;
     private int idec;
     private int idUe;
     private int nbrtd;
     private int nbrcm;
     private int idIntervenant;
     private int anneePromotion;
     private String commentaire;
     private String nom;
     private String code;
     private String gradeFormation; // Master, Licence
     private String niveauFormation; // 1,2,3
     private String filiereFormation; // Info
     private String parcoursFormation; // Miage
     private String typeeFormation; // Apprentissage ou Classique
     private float coeff;
     private boolean publier;
     private List<Controle> controles;
     private List<EcEtudiant> etudiants;

    public EcIntervenant(int idec, int idF, int idP,int idUe,
            String nom, String code, float coeff, 
            int nbrtd, int nbrcm,int idIntervenant,int anneePromotion,
            String gradeFormation,String niveauFormation,String filiereFormation,
            String parcoursFormation, String typeeFormation
            ) {
        this.idec = idec;
        this.idF = idF;
        this.idP =idP;
        this.idUe = idUe;
        this.nom = nom;
        this.code = code;
        this.coeff = coeff;
        this.nbrtd = nbrtd;
        this.nbrcm = nbrcm;
        this.idIntervenant = idIntervenant;
        this.anneePromotion = anneePromotion;
        this.gradeFormation = gradeFormation;
        this.niveauFormation = niveauFormation;
        this.filiereFormation = filiereFormation;
        this.parcoursFormation = parcoursFormation;
        this.typeeFormation = typeeFormation;
        this.setEtudiants();
        this.setControles();
        this.setPublier();

    }

    public String getCommentaireByEtudiantId(int idEtudiant)
    {
        
        String commentaireEtudiant = "-";
         try {
             commentaireEtudiant = EcsIntervenantServices.getCommentaireByEtudiantId(this.idec, idEtudiant, this.idP);
         } catch (SQLException ex) {
             Logger.getLogger(EcIntervenant.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(EcIntervenant.class.getName()).log(Level.SEVERE, null, ex);
         }
         //System.out.println("Dans Ec intervenant"+commentaireEtudiant);
         return commentaireEtudiant;
    }
    
    
    public String getGradeFormation() {
        return gradeFormation;
    }

    public void setGradeFormation(String gradeFormation) {
        this.gradeFormation = gradeFormation;
    }

    public String getNiveauFormation() {
        return niveauFormation;
    }

    public void setNiveauFormation(String niveauFormation) {
        this.niveauFormation = niveauFormation;
    }

    public String getFiliereFormation() {
        return filiereFormation;
    }

    public void setFiliereFormation(String filiereFormation) {
        this.filiereFormation = filiereFormation;
    }

    public String getParcoursFormation() {
        return parcoursFormation;
    }

    public void setParcoursFormation(String parcoursFormation) {
        this.parcoursFormation = parcoursFormation;
    }

    public String getTypeeFormation() {
        return typeeFormation;
    }

    public void setTypeeFormation(String typeeFormation) {
        this.typeeFormation = typeeFormation;
    }
   
    public float calculMoyenneEc()
    {
        // requete ou java pour la partie intervenant
        return 10;
    }
    
//    public float calculMoyenneEcEtudiant()
//    {
//        float moy =0;
//        float coeffTotal = 0;
//        // pas de requete calcule java
//        for (Controle controle : this.controles) 
//        {
//            coeffTotal+=controle.getCoefficient();
//            for (Note note : controle.getNotes()) 
//            {
//                moy+=note.getNote()*controle.getCoefficient();
//            }
//	}
//        
//        return moy/coeffTotal;
//    }
    
    public float calculMoyenneEcByEtudiantId(int idEtudiant)
    {
        float moy =0;
         try {
             moy=EcsIntervenantServices.calculMoyenneEcByEtudiantId(idEtudiant,this.idec,this.idP);
         } catch (SQLException ex) {
             Logger.getLogger(EcIntervenant.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(EcIntervenant.class.getName()).log(Level.SEVERE, null, ex);
         }
        
        return moy;
    }
    
    public int getAnneePromotion() {
        return anneePromotion;
    }

    public void setAnneePromotion(int anneePromotion) {
        this.anneePromotion = anneePromotion;
    }

    public List<EcEtudiant> getEtudiants() {
        return etudiants;
    }

    public void setEtudiants() {
         try {
             this.etudiants = EcsIntervenantServices.getEtudiant(this.idec,this.anneePromotion);
         } catch (SQLException ex) {
             Logger.getLogger(EcIntervenant.class.getName()).log(Level.SEVERE, null, ex);
         }
    }

    public String getCommentaire() {
        return commentaire;
    }

//    public void setCommentaire() {
//         try {
//             this.commentaire=EcServices.getCommentaire(this.idec,this.idP);
//         } catch (SQLException ex) {
//             Logger.getLogger(Ec.class.getName()).log(Level.SEVERE, null, ex);
//         } catch (Exception ex) {
//             Logger.getLogger(Ec.class.getName()).log(Level.SEVERE, null, ex);
//         }
//    }

    public int getIdUe() {
        return idUe;
    }

    public void setIdUe(int idUe) {
        this.idUe = idUe;
    }

    public int getIdF() {
        return idF;
    }

    public void setIdF(int idF) {
        this.idF = idF;
    }

    public int getIdP() {
        return idP;
    }

    public void setIdP(int idP) {
        this.idP = idP;
    }

    public boolean isPublier() {
        return publier;
    }

    public void setPublier(){
         try {
             this.publier = EcServices.setPublier(this.idec, this.idF, this.idP);
         } catch (SQLException ex) {
             Logger.getLogger(Ec.class.getName()).log(Level.SEVERE, null, ex);
         }
    }

    public float getCoeff() {
        return coeff;
    }

    public void setCoeff(float coeff) {
        this.coeff = coeff;
    }

    public int getNbrtd() {
        return nbrtd;
    }

    public void setNbrtd(int nbrtd) {
        this.nbrtd = nbrtd;
    }

    public int getNbrcm() {
        return nbrcm;
    }

    public void setNbrcm(int nbrcm) {
        this.nbrcm = nbrcm;
    }
    
    
    public int getIdec() {
        return this.idec;
    }
    
    public void setIdec(int idec) {
        this.idec = idec;
    }
    public String getNom() {
        return this.nom;
    }
    
    public void setNom(String nom) {
        this.nom = nom;
    }
    public String getCode() {
        return this.code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }

    public List<Controle> getControles() {
        return this.controles;
    }

    public int getIdIntervenant() {
        return idIntervenant;
    }

    public void setIdIntervenant(int idIntervenant) {
        this.idIntervenant = idIntervenant;
    }
    
    public void setControles() {
         try {
             this.controles = EcServices.getControles(this.idP,this.idec,false,0);
         } catch (SQLException ex) {
             Logger.getLogger(Ec.class.getName()).log(Level.SEVERE, null, ex);
         }
    }
    
        
    public Controle getControleById(int idControle)
    {
        Controle tmp = null;
        for (int i = 0; i < this.controles.size(); i++) {
		if(this.controles.get(i).getIdcontrole()==idControle)
                {
                    tmp=this.controles.get(i);
                }
	}
        return tmp;
    }
}
